package com.pkx.guide.info.service.impl;

import com.pkx.guide.info.entity.TInfoGuidePlayListDevice;
import com.pkx.guide.info.mapper.TInfoGuidePlayListDeviceMapper;
import com.pkx.guide.info.service.TInfoGuidePlayListDeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 诱导屏播放表设备关联表 服务实现类
 *
 * @author sunsy
 * @since 2023-12-20
 */
@Service
public class TInfoGuidePlayListDeviceServiceImpl extends ServiceImpl<TInfoGuidePlayListDeviceMapper, TInfoGuidePlayListDevice> implements TInfoGuidePlayListDeviceService {

    /**
     * 分页列表
     *
     * @param tInfoGuidePlayListDevice
     * @return
     */
    @Override
    public IPage<TInfoGuidePlayListDevice> pageList(Page page, TInfoGuidePlayListDevice tInfoGuidePlayListDevice) {
        LambdaQueryWrapper<TInfoGuidePlayListDevice> lambdaQueryWrapper = new QueryWrapper<TInfoGuidePlayListDevice>().lambda();
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param tInfoGuidePlayListDevice
     * @return
     */
    @Override
    public List<TInfoGuidePlayListDevice> listByEntity(TInfoGuidePlayListDevice tInfoGuidePlayListDevice) {
        LambdaQueryWrapper<TInfoGuidePlayListDevice> lambdaQueryWrapper = new QueryWrapper<TInfoGuidePlayListDevice>().lambda();
        lambdaQueryWrapper.eq(tInfoGuidePlayListDevice.getPlayListId() != null, TInfoGuidePlayListDevice::getPlayListId, tInfoGuidePlayListDevice.getPlayListId());
        lambdaQueryWrapper.eq(tInfoGuidePlayListDevice.getGuideId() != null, TInfoGuidePlayListDevice::getGuideId, tInfoGuidePlayListDevice.getGuideId());
        lambdaQueryWrapper.eq(TInfoGuidePlayListDevice::getDelFlg, 0);
        return list(lambdaQueryWrapper);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public TInfoGuidePlayListDevice selectById(Integer id) {
        return getById(id);
    }

    /**
     * 保存
     *
     * @param tInfoGuidePlayListDevice
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveTInfoGuidePlayListDevice(TInfoGuidePlayListDevice tInfoGuidePlayListDevice) {
        return save(tInfoGuidePlayListDevice);
    }

    /**
     * 修改
     *
     * @param tInfoGuidePlayListDevice
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modify(TInfoGuidePlayListDevice tInfoGuidePlayListDevice) {
        return updateById(tInfoGuidePlayListDevice);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(Integer id) {
        if (id == null){
            return false;
        }
        LambdaUpdateWrapper<TInfoGuidePlayListDevice> lambdaUpdateWrapper = new UpdateWrapper<TInfoGuidePlayListDevice>().lambda()
            .eq(TInfoGuidePlayListDevice::getId, id)
            .set(TInfoGuidePlayListDevice::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }

    /**
     * 删除
     *
     * @param playListId
     * @return
     */
    @Override
    public Boolean deleteByPlayListId(Integer playListId){
        if (playListId == null){
            return false;
        }
        LambdaUpdateWrapper<TInfoGuidePlayListDevice> lambdaUpdateWrapper = new UpdateWrapper<TInfoGuidePlayListDevice>().lambda()
                .eq(TInfoGuidePlayListDevice::getPlayListId, playListId)
                .set(TInfoGuidePlayListDevice::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }
}
